//
//  AuthenTypeItemVM.swift
//  kxf
//
//  Created by Mac on 2024/3/6.
//

import Foundation
import UIKit

class AuthenTypeItemVM: UIView {
    
    let selfHeight = kFitWidth(85)
    var isSelected = false
    
    var tapBlock:(()->())?

    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: frame.origin.y, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(tapAction))
        self.addGestureRecognizer(tap)
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var bgView : UIView = {
        let vi = UIView()
        vi.layer.cornerRadius = kFitWidth(12)
        vi.clipsToBounds = true
        vi.isUserInteractionEnabled = true
        vi.backgroundColor = WHColorWithAlpha(colorStr: "DBDBDB", alpha: 0.1)
        
        return vi
    }()
    lazy var iconImgView : UIImageView = {
        let img = UIImageView()
        img.image = UIImage.init(named: "authen_type_icon")
        
        return img
    }()
    lazy var titleLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 16, weight: .medium)
        
        return lab
    }()
    lazy var detailLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 14, weight: .regular)
        
        return lab
    }()
    
}

extension AuthenTypeItemVM{
    func setSelected(isSelect:Bool){
        isSelected = isSelect
        
        bgView.backgroundColor = isSelected ? WHColorWithAlpha(colorStr: "F10E0E", alpha: 0.1) : WHColorWithAlpha(colorStr: "DBDBDB", alpha: 0.1)
    }
    @objc func tapAction() {
        self.setSelected(isSelect: true)
        if self.tapBlock != nil{
            self.tapBlock!()
        }
    }
}
extension AuthenTypeItemVM{
    func initUI() {
        addSubview(bgView)
        bgView.addSubview(iconImgView)
        bgView.addSubview(titleLab)
        bgView.addSubview(detailLab)
        
        setConstrait()
    }
    func setConstrait(){
        bgView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.width.equalTo(kFitWidth(337))
            make.height.equalTo(kFitWidth(75))
            make.top.equalTo(kFitWidth(10))
        }
        iconImgView.snp.makeConstraints { make in
            make.centerY.lessThanOrEqualToSuperview()
            make.width.height.equalTo(kFitWidth(40))
            make.left.equalTo(kFitWidth(9))
        }
        titleLab.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(62))
            make.top.equalTo(kFitWidth(15))
        }
        detailLab.snp.makeConstraints { make in
            make.left.equalTo(titleLab)
            make.top.equalTo(titleLab.snp.bottom).offset(kFitWidth(3))
        }
    }
}
